home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / turbocadtest6.vbs < prev    next >
Encoding:
Text File  |  2001-10-16  |  13.6 KB  |  607 lines

  1. Option Explicit
  2.  
  3. Const imsiPolyline = 11
  4. Const imsi3DMesh = 3
  5.  
  6. Dim tcApp
  7. Dim tcDwgs
  8. Dim tcDwg
  9. Dim tcGrs
  10. Dim tcVw
  11.  
  12. Dim fso
  13. Dim f
  14. Dim fName
  15. Dim rootPath
  16.  
  17. Dim bSolid
  18.  
  19. Sub DumpProp(tcProp)
  20.  
  21.    f.WriteLine tcProp.Name + " " + CStr(tcProp.Value)
  22.  
  23. end sub
  24.  
  25. Sub DumpProps(tcProps)
  26.  
  27. Dim tcPropType
  28. Dim tcProp
  29. Dim idProp
  30. Dim bNew 
  31.  
  32.    On Error Resume Next
  33.    Set tcPropType = tcProps("RegenMethod")
  34.    fName = rootPath & "\" & tcPropType.Value & ".txt"
  35.  
  36.    bNew = fso.FileExists(fName)
  37.    Set f = fso.OpenTextFile(fName, 8, True)
  38.    if (Err.Number <> 0) then
  39.         MsgBox Err.Description
  40.         Exit Sub
  41.    end if
  42.  
  43.    if (Not bNew) then
  44.        f.WriteLine tcPropType.Value
  45.    else
  46.        f.WriteLine ""
  47.    end if
  48.  
  49.    for each tcProp in tcProps
  50.        idProp = tcProp.ID
  51.        if (Err.Number <> 0) then
  52.  
  53.            DumpProp tcProp
  54.  
  55.        end if
  56.    next
  57.    
  58.    f.Close
  59.  
  60. end sub
  61.  
  62. Sub CreateMesh()
  63.  
  64. Dim tcGrMesh
  65. Dim tcPropsMesh
  66. Dim tcVrtsMesh
  67. Dim cx
  68. Dim cy
  69. Dim dx
  70. Dim dy
  71. Dim dz
  72. Dim x
  73. Dim y
  74. Dim z
  75. Dim indX
  76. Dim indY
  77.  
  78.     cx = 9
  79.     cy = 9
  80.     dx = 1
  81.     dy = 1
  82.  
  83.     ' add the cube graphic
  84.     Set tcGrMesh = tcGrs.Add(imsi3DMesh, "TCW70MESH")
  85.     
  86.     ' add points as verices that will define the box
  87.     Set tcVrtsMesh = tcGrMesh.Vertices
  88.  
  89.     x = 0
  90.     y = 0
  91.     z = 0
  92.  
  93.     Randomize
  94.     With tcVrtsMesh
  95.         for indY = 0 to cy
  96.             for indX = 0 to cx
  97.                 .Add x, y, z, true, true, true, true
  98.                 z = 0 '21 * Rnd - 10
  99.                 x = x + dx
  100.             next
  101.             x = 0
  102.             y = y + dy
  103.         next
  104.     End With    
  105.  
  106.     tcGrMesh.Draw
  107.     'DumpProps tcPropsMesh
  108.  
  109.     Set tcPropsMesh = Nothing
  110.     Set tcVrtsMesh = Nothing
  111.     Set tcGrMesh = Nothing
  112.      
  113. End Sub
  114.  
  115. Sub CreateCube()
  116.  
  117. Dim tcGrCube
  118. Dim tcPropsCube
  119. Dim tcVrtsCube
  120.  
  121.     ' add the cube graphic
  122.     Set tcGrCube = tcGrs.Add(, "TCW40CUBE")
  123.     
  124.    ' it is need to set property to make correct graphic
  125.     Set tcPropsCube = tcGrCube.Properties
  126.     with tcPropsCube
  127.         .Item("Solid") = bSolid
  128.     end with
  129.  
  130.     ' add points as verices that will define the box
  131.     Set tcVrtsCube = tcGrCube.Vertices
  132.     With tcVrtsCube
  133.         .Add 1, 1, 0
  134.         .Add 2, 1, 0
  135.         .Add 1, 2, 0
  136.         .Add 1, 2, 1
  137.     End With    
  138.  
  139.     tcGrCube.Draw
  140.     DumpProps tcPropsCube
  141.  
  142.     Set tcPropsCube = Nothing
  143.     Set tcVrtsCube = Nothing
  144.     Set tcGrCube = Nothing
  145.      
  146. End Sub
  147.  
  148.  
  149. Sub CreateCone()
  150.  
  151. Dim tcGrCone
  152. Dim tcGrsCone
  153. Dim tcPropsCone
  154. Dim tcGr1
  155. Dim tcGr2
  156. Dim tcVrts
  157.  
  158.     ' create the circle graphic that will be
  159.     ' a profile (base) for Cone
  160.     Set tcGr1 = tcGrs.AddCircleCenterAndPoint(1, 1, 0, 2, 2, 0) 
  161.  
  162.    ' add the point graphic 
  163.    ' that will be vertex of cone
  164.     Set tcGr2 = tcGrs.Add(imsiPolyline)
  165.     tcGr2.Vertices.Add 1, 1, 4
  166.  
  167.    ' add the graphic of type TCW40LOFT
  168.    ' that will be a Cone
  169.     Set tcGrCone = tcGrs.Add(, "TCW40LOFT")
  170.  
  171.    ' it is need to set property to make correct graphic
  172.     Set tcPropsCone = tcGrCone.Properties
  173.     with tcPropsCone
  174.         .Item("Solid") = bSolid
  175.         .Item("$SMOOTH") = 0
  176.     end with
  177.  
  178.    ' add the point as vertex that 
  179.    ' that will be a projection vertex
  180.    ' of cone on base graphic plane
  181.     tcGrCone.Vertices.Add 1, 1, 0
  182.  
  183.    ' add the profile grahics to graphics collection of cone
  184.     Set tcGrsCone = tcGrCone.Graphics
  185.     tcGrs.Remove(tcGr1.Index)    ' *
  186.     tcGrs.Remove(tcGr2.Index)    ' *
  187.  
  188.     with tcGrsCone
  189.         .AddGraphic tcGr1
  190.         .AddGraphic tcGr2
  191.     end with
  192.  
  193.     tcGrCone.Draw
  194.     DumpProps tcPropsCone
  195.  
  196.     Set tcGr1 = Nothing
  197.     Set tcGr2 = Nothing
  198.  
  199.     Set tcGrsCone = Nothing
  200.     Set tcPropsCone = Nothing
  201.     Set tcGrCone = Nothing
  202.     
  203. End Sub
  204.  
  205. Public Sub CreatePrizm()
  206.  
  207. Dim tcGrPrizm
  208. Dim tcGrsPrizm
  209. Dim tcPropsPrizm
  210. Dim tcGr1
  211. Dim tcGr2
  212.  
  213.    ' create the graphic that will be profile
  214.    ' (first base) for Prizm
  215.    Set tcGr1 = tcGrs.AddLineRectangle(1, 1, 0, 2, 2, 0)
  216.    
  217.    ' create the graphic that will be profile
  218.    ' (second base) for Prizm
  219.    Set tcGr2 = tcGrs.AddLineRectangle(1.2, 1.2, 0, 1.8, 1.8, 0) 
  220.    tcGr2.MoveRelative 0, 0, 2
  221.  
  222.    ' add the graphic of type TCW40LOFT
  223.    ' that will be a Prizm
  224.    Set tcGrPrizm = tcGrs.Add(, "TCW40LOFT")
  225.  
  226.    ' it is need to set properties to make correct graphic
  227.     Set tcPropsPrizm = tcGrPrizm.Properties
  228.     With tcPropsPrizm
  229.        .Item("Solid") = bSolid
  230.        .Item("$SMOOTH") = 0
  231.     End With    
  232.  
  233.    ' add the profile grahics to graphics collection of Prizm
  234.     tcGrs.Remove(tcGr1.Index)   ' *
  235.     tcGrs.Remove(tcGr2.Index)   ' *
  236.  
  237.     Set tcGrsPrizm = tcGrPrizm.Graphics
  238.     With tcGrsPrizm
  239.         .AddGraphic tcGr1
  240.         .AddGraphic tcGr2
  241.     End With
  242.     
  243.     '? To avoid one bug we now have in TurboCAD
  244.     '? for prizm we should add and them remove a one vertex
  245.     
  246.     '? Set Ver = Gr.Vertices.Add(0, 0, 0)
  247.     '? Set Ver = Gr.Vertices.Remove(0)
  248.  
  249.     tcGrPrizm.Draw
  250.     DumpProps tcPropsPrizm
  251.  
  252.     Set tcGr1 = Nothing
  253.     Set tcGr2 = Nothing
  254.  
  255.     Set tcGrsPrizm = Nothing
  256.     Set tcPropsPrizm = Nothing
  257.     Set tcGrPrizm = Nothing
  258.     
  259. End Sub
  260.  
  261. Sub CreateNormalExtrusion()
  262.  
  263. Dim tcGrExtrusion
  264. Dim tcPropsExtrusion
  265. Dim tcVrtsExtrusion
  266.  
  267. Dim tcGr1
  268.  
  269.     ' create the graphic that will be profile
  270.     ' (base) for Extrusion
  271.     Set tcGr1 = tcGrs.AddLineRectangle(1, 1, 0, 2, 2, 0) 
  272.  
  273.     ' add the graphic of type TCW40EXTRUDE
  274.     ' that will be Extrusion
  275.     Set tcGrExtrusion = tcGrs.Add(, "TCW40EXTRUDE")  
  276.  
  277.    ' it is need to set properties to make correct graphic
  278.     Set tcPropsExtrusion = tcGrExtrusion.Properties
  279.     With tcPropsExtrusion
  280.         .Item("Solid") = bSolid
  281.         .Item("$PIPE") = 1 
  282. '       .Item("$APPROCSIMCURVE") = 19
  283.     End With
  284.  
  285.     ' add the base grahic to graphics collection of Extrusion
  286.     tcGrs.Remove tcGr1.Index ' *
  287.     tcGrExtrusion.Graphics.AddGraphic tcGr1
  288.     
  289.    ' add points as Vertices to the Extrusionc
  290.    ' to define extrusion path (segment of extrude)
  291.    ' **
  292.    Set tcVrtsExtrusion = tcGrExtrusion.Vertices
  293.    tcVrtsExtrusion.UseWorldCS = True
  294.    With tcVrtsExtrusion
  295.       .Add 1, 1, 0
  296.       .Add 1, 1, 3
  297.    End With
  298.  
  299.    tcGrExtrusion.Draw
  300.    DumpProps tcPropsExtrusion
  301.  
  302.    Set tcGr1 = Nothing
  303.  
  304.    Set tcPropsExtrusion = Nothing
  305.    Set tcVrtsExtrusion = Nothing
  306.    Set tcGrExtrusion = Nothing
  307.  
  308. End Sub
  309.  
  310. Sub CreateRigidExtrusion()
  311.  
  312. Dim x
  313. Dim y
  314. Dim z
  315.  
  316. Dim tcGrExtrusion
  317. Dim tcPropsExtrusion
  318. Dim tcVrtsExtrusion
  319.  
  320. Dim tcGr1
  321.  
  322.     ' create the graphic that will be profile
  323.     ' (base) for extrude
  324.     Set tcGr1 = tcGrs.AddLineRectangle(1, 1, 0, 2, 2, 0) 
  325.  
  326.     ' add the graphic of type TCW40EXTRUDE
  327.     ' that will be Extrusion
  328.     Set tcGrExtrusion = tcGrs.Add(, "TCW40EXTRUDE")  
  329.  
  330.    ' it is need to set properties to make correct graphic
  331.     Set tcPropsExtrusion = tcGrExtrusion.Properties
  332.     With tcPropsExtrusion
  333.         .Item("Solid") = bSolid
  334.         .Item("$PIPE") = 0
  335. '       .Item("$APPROCSIMCURVE") = 19
  336.     End With
  337.  
  338.     ' add the base grahic to graphics collection of Extrusion
  339.     tcGrs.Remove tcGr1.Index ' *
  340.     tcGrExtrusion.Graphics.AddGraphic tcGr1
  341.     
  342.    ' add points as Vertices to the Extrusionc
  343.    ' to define extrusion path (segment of extrude)
  344.    ' **
  345.    Set tcVrtsExtrusion = tcGrExtrusion.Vertices
  346.    tcVrtsExtrusion.UseWorldCS = True    
  347.  
  348.    x = 1.5
  349.    y = 1.5
  350.    z = 0
  351.  
  352.    With tcVrtsExtrusion
  353.  
  354.        .Add x, y, z
  355.        x = x + 1
  356.        z = z + 1
  357.        .Add x, y, z
  358.        y = y + 1
  359.        .Add x, y, z
  360.        z = z + 1
  361.        .Add x, y, z
  362.  
  363.    End With
  364.  
  365.    tcGrExtrusion.Draw
  366.    DumpProps tcPropsExtrusion
  367.    Set tcGr1 = Nothing
  368.  
  369.    Set tcPropsExtrusion = Nothing
  370.    Set tcVrtsExtrusion = Nothing
  371.    Set tcGrExtrusion = Nothing
  372.  
  373. End Sub
  374.  
  375. Sub CreateHemiSphere()
  376.  
  377. Dim tcGrHemiSphere
  378. Dim tcPropsHemiSphere
  379. Dim tcVrtsHemiSphere
  380.  
  381.     ' add the graphic of type TCW40SPHERE
  382.     ' that will be HemiSphere
  383.     Set tcGrHemiSphere = tcGrs.Add(, "TCW40SPHERE")
  384.    
  385.    ' it is need to set properties to make correct graphic
  386.     Set tcPropsHemiSphere = tcGrHemiSphere.Properties
  387.     With tcPropsHemiSphere
  388.        .Item("Solid") = bSolid
  389.        .Item("$HEMISPHERE") = 1
  390. '      .Item("$MERIDIANDENSITY") = 45
  391. '      .Item("$PARALLELDENSITY") = 67
  392. '      .Item("$SMOOTH") = 1
  393.     End With
  394.     
  395.     Set tcVrtsHemiSphere = tcGrHemiSphere.Vertices
  396.     With tcVrtsHemiSphere
  397.         .Add 1, 1, 1
  398.         .Add -1, -1, 1
  399.     End With 
  400.  
  401.     tcGrHemiSphere.Draw
  402.     DumpProps tcPropsHemiSphere
  403.  
  404.     Set tcVrtsHemiSphere = Nothing
  405.     Set tcPropsHemiSphere = Nothing
  406.     
  407.     Set tcGrHemiSphere = Nothing
  408.     
  409. End Sub
  410.  
  411. Sub CreateSphere()
  412.  
  413. Dim tcGrSphere
  414. Dim tcPropsSphere
  415. Dim tcVrtsSphere
  416.  
  417.     ' add the graphic of type TCW40SPHERE
  418.     ' that will be Sphere
  419.     Set tcGrSphere = tcGrs.Add(, "TCW40SPHERE")
  420.    
  421.    ' it is need to set properties to make correct graphic
  422.     Set tcPropsSphere = tcGrSphere.Properties
  423.     With tcPropsSphere
  424.        .Item("Solid") = bSolid
  425.        .Item("$HEMISPHERE") = 0
  426. '      .Item("$MERIDIANDENSITY") = 45
  427. '      .Item("$PARALLELDENSITY") = 67
  428. '      .Item("$SMOOTH") = 1
  429.     End With
  430.     
  431.     Set tcVrtsSphere = tcGrSphere.Vertices
  432.     With tcVrtsSphere
  433.         .Add 1, 1, 1
  434.         .Add -1, -1, 1
  435.     End With 
  436.  
  437.     tcGrSphere.Draw
  438.     DumpProps tcPropsSphere
  439.  
  440.     Set tcVrtsSphere = Nothing
  441.     Set tcPropsSphere = Nothing
  442.     
  443.     Set tcGrSphere = Nothing
  444.     
  445. End Sub
  446.  
  447. Sub CreateRevolve()
  448.  
  449. Dim tcGrRevolve
  450. Dim tcPropsRevolve
  451. Dim tcVrtsRevolve
  452.  
  453. Dim tcGr1
  454.  
  455.     ' create the graphic that will be profile
  456.     ' (base) for Revolve
  457.     Set tcGr1 = tcGrs.AddLineSingle(0, 0, 0, 0.5, 0, 0)
  458.     tcGr1.Vertices.Add 0.5, 0.5, 0
  459.     tcGr1.Close
  460.  
  461.     ' create graphic of type TCW40SPIN
  462.     ' that will be Revolve
  463.     Set tcGrRevolve = tcGrs.Add(, "TCW40SPIN") 
  464.  
  465.     ' it is need to set properties to make correct graphic
  466.     Set tcPropsRevolve = tcGrRevolve.Properties
  467.     With tcPropsRevolve
  468.        .Item("Solid") = bSolid
  469. ' ?    .Item("$ROTATIONANGLE") = 90
  470.        .Item("$ROTATIONANGLE") = 360
  471.        .Item("$SPIRENUMBER") = 5
  472.        .Item("$STEP") = 1
  473. '      .Item("$APPROCSIMCURVE") = 56
  474. '      .Item("$SMOOTH") = 1
  475.     End with
  476.  
  477.    ' add the base grahic to graphics collection of Revolve
  478.     tcGrs.Remove tcGr1.Index ' "
  479.     tcGrRevolve.Graphics.AddGraphic tcGr1
  480.  
  481.     ' add two points to the define Revolve axis
  482.     Set tcVrtsRevolve = tcGrRevolve.Vertices
  483.     tcVrtsRevolve.UseWorldCS = True
  484.     With tcVrtsRevolve
  485.         .Add 1, 1, 0
  486.         .Add 1, 2, 0
  487.     End With     
  488.  
  489.     tcGrRevolve.Draw
  490.     DumpProps tcPropsRevolve
  491.  
  492.     Set tcGr1 = Nothing
  493.  
  494.     Set tcPropsRevolve = Nothing
  495.     Set tcVrtsRevolve  = Nothing
  496.     Set tcGrRevolve    = Nothing
  497.  
  498. End Sub
  499.  
  500.     Set fso = CreateObject("Scripting.FileSystemObject")
  501.     Set tcApp = CreateObject("TurboCAD.Application")
  502.     rootPath = tcApp.Path    
  503.  
  504.     bSolid = False
  505.     Set tcDwgs = tcApp.Drawings
  506.  
  507.     if (tcDwgs.Count > 0) then
  508.  
  509.         Set tcDwg = tcApp.ActiveDrawing
  510.         Set tcVw = tcDwg.ActiveView
  511.         Set tcGrs = tcDwg.Graphics
  512.  
  513.         CreateCube
  514.         CreateCone
  515.         CreatePrizm
  516.         CreateNormalExtrusion
  517.         CreateRigidExtrusion
  518.         CreateHemiSphere
  519.         CreateSphere
  520.         CreateRevolve
  521.  
  522.         tcVw.ZoomToExtents
  523.     end if
  524.  
  525.     MsgBox "Done"
  526.     
  527.     Set tcDwgs = Nothing
  528.     Set tcApp = Nothing
  529.  
  530. '******************** Notes *******************************************
  531. '
  532. ' * - it is need to remove the Graphic Object from Graphics collection
  533. '     before add to another because Graphic Object can't belongs 2 different
  534. '      Graphics Colloections
  535. '
  536. ' ** - extrusion path will be automaticalle recalculated and vill be centered
  537. '      relatively to geometric center of the base extrusion profile
  538. '
  539. '
  540. '==============================================
  541. ' TCW40CUBE
  542. '==============================================
  543. ' Material                3D Page, Material
  544. ' Solid                    3D Page, Solid/Surface
  545.  
  546. ' $ACISCOSMETIC            Not used
  547.  
  548. '==============================================
  549. ' TCW40LOFT
  550. '==============================================
  551. ' Material                3D Page, Material
  552. ' Solid                    3D Page, Solid/Surface
  553.  
  554. ' $ACISCOSMETIC            Not used
  555. ' $SOLID                Not used
  556.  
  557. ' $APPROCSIMCURVE        Lofting Shape Page, Number of approximation lines
  558. ' $SMOOTH                Lofting Shape Page, Smooth
  559. ' $MINTWIST                Lofting Shape Page, Minimize Twist
  560.  
  561. '==============================================
  562. ' TCW40EXTRUDE
  563. '==============================================
  564. ' Material                3D Page, Material
  565. ' Solid                    3D Page, Solid/Surface
  566.  
  567. ' $ACISCOSMETIC            Not used
  568. ' $SOLID                Not used
  569.  
  570. ' $PIPE                    Local Menu option,  Normal Path
  571. ' $APPROCSIMCURVE        Extrude Shape Page, Number of approximation lines
  572. ' $SMOOTH                Extrude Shape Page, Smooth
  573. ' $TWISTANGLE            Extrude Shape Page, Twist Angle (degrees in UI, but radians for programming)
  574.  
  575. '==============================================
  576. ' "TCW40SPHERE"
  577. '==============================================
  578. '
  579. ' Material                3D Page, Material
  580. ' Solid                    3D Page, Solid/Surface
  581. '
  582. ' $ACISCOSMETIC            not used
  583. '
  584. ' $HEMISPHERE            Sphere tool/Hemisphere tool
  585. '
  586. ' $PARALLELDENSITY        Sphere Page, Number of latitudinal segments
  587. ' $MERIDIANDENSITY        Sphere Page, Number of longitudinal segments
  588. ' $SMOOTH                 Sphere Page, Smooth
  589.  
  590. '==============================================
  591. ' TCW40SPIN
  592. '==============================================
  593. ' Material                3D Page, Material
  594. ' Solid                    3D Page, Solid/Surface
  595. '
  596. ' $ACISCOSMETIC            not used
  597. ' $SPIRENUMBER            not used
  598.  
  599. ' $ROTATIONCOPY            Sections per spiral coil
  600. ' $APPROCSIMCURVE        Number of approximation lines
  601. ' $ROTATIONANGLE        Angle of rotation (degrees in UI, but radians for programming)
  602. ' $SMOOTH                Smooth
  603. ' $STEP                    Spiral pitch
  604. ' $HANDINESS            Counterclockwise/Clockwise
  605. ' $COILNUMBER            Number of coils
  606.  
  607.